// pages/ht_moban/ht_moban.js
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    currentTab:0,
    jl_tcan:[],
    page:1,
    its:0
  },
  taocan_jl:function(e){
    wx.navigateTo({
      url: '../taocan_jl/taocan_jl',
    })
  },
  guanbi:function(e){
    this.setData({
      xians:"display:none",
    })
  },
  switchNav1(event){
    var that = this;
    var cur = event.currentTarget.dataset.current; 
    console.log(cur)
    var singleNavWidth1 = this.data.windowWidth / 5;
    var tu = (cur - 2) * singleNavWidth1
    this.setData({
      navScrollLeft1: (cur - 2) * singleNavWidth1+40
    })      
    if (this.data.currentTab1 == cur) {
      this.setData({
        currentTab1: "999",
    })
        return false;
    } else {
        this.setData({
            currentTab1: cur,
        })
    }
  },
  /**
   * 生命周期函数--监听页面加载
   */
  gma:function(e){
     wx.navigateTo({
       url: '../ht_moban1/ht_moban1',
     })
  },
  onLoad: function (options) {
    var that = this;
    wx.request({
      url: app.globalData.url_l + 'api/member/set_meal',
      method: 'post',
     data:{
        uid:app.globalData.uid,
        corpid:app.globalData.corpid,
        type:"使用中",
        page:1
     },
      header: {
        'content-type': 'application/x-www-form-urlencoded'
      },
      success: function (res) {
         console.log(res)
         if(res.data.data==''){
          wx.showToast({
            title: '没有更多数据！',
            icon: 'none',
            duration: 2000
          })
         }
         that.setData({
          jl_tcan:res.data.data,
          shu:res.data.total
         })
      }
    })
    wx.request({
      url: app.globalData.url_l + 'api/member/ht_jilu',
      method: 'post',
     data:{
        uid:app.globalData.uid,
     },
      header: {
        'content-type': 'application/x-www-form-urlencoded'
      },
      success: function (res) {
         console.log(res)
         that.setData({
          tb_sj:res.data,
          ht_jl:res.data.res
         })
      }
    })
    wx.request({
      url: app.globalData.url_l + 'api/member/zhangdan',
      method: 'post',
     data:{
        uid:app.globalData.uid,
        state:3,
        shu:0
     },
      header: {
        'content-type': 'application/x-www-form-urlencoded'
      },
      success: function (res) {
         console.log(res)
         that.setData({
           zhangdna:res.data,

         })
      }
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  onPullDownRefresh: function () {
    var that = this;
    that.data.page=1
    wx.showToast({
      title: "数据加载中...",
      icon: 'loading',
      duration: 2000
    });
      wx.request({
        url: app.globalData.url_l + 'api/member/set_meal',
        method: 'post',
       data:{
          uid:app.globalData.uid,
          corpid:app.globalData.corpid,
          type:"使用中",
          page:1
        },
        header: {
          'content-type': 'application/x-www-form-urlencoded;charset=utf-8',
        },
        success: function (res) {
          wx.hideNavigationBarLoading();
          wx.stopPullDownRefresh();
          if (res.data.data == '' || res.data.data == 0) {
            wx.showToast({
              title: '没有更多数据了！',
              icon: 'none',
              duration: 2000
            })
          }
          that.setData({
            jl_tcan: res.data.data,
            shu:res.data.total
          })
        }
  
      })
    
   
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    var that = this;
    //页码
    that.data.page++;
    console.log(that.data.page)
    // 加载数据,模拟耗时操作
    wx.showToast({
      title: "数据加载中...",
      icon: 'loading',
      duration: 2000
    });
    //请求接口
    wx.request({
      url: app.globalData.url_l + 'api/member/set_meal',
      method: 'post',
     data:{
        uid:app.globalData.uid,
        corpid:app.globalData.corpid,
        type:"使用中",
        page: that.data.page
      },
      header: {
        'content-type': 'application/x-www-form-urlencoded;charset=utf-8',
      },
      success: function (res) {
        console.log(res)
        wx.hideNavigationBarLoading();
        wx.stopPullDownRefresh();
        if (res.data.data == '' || res.data.data == 0) {
          wx.showToast({
            title: '没有更多数据了！',
            icon: 'none',
            duration: 2000
          })
        }
        for (var i = 0; i < res.data.data.length; i++) {
          that.data.jl_tcan.push(res.data.data[i]);
        }
        that.setData({
          jl_tcan: that.data.jl_tcan,
          shu:res.data.total
        })
      }

    })
  },
  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})